#pragma once
#include "IUpdateable.hpp"

namespace rh
{

	template <class T, class Enum>
	class StateMachineState : public rh::IUpdateable
	{

		typedef void (T::*InitializeFncPtr) (void);
		typedef Enum (T::*CleanupFncPtr)(void);
		typedef void (T::*UpdateFncPtr) (const sf::Time&, const sf::Time&);

	protected:
		InitializeFncPtr _initializationPtr;
		UpdateFncPtr _updatePtr;
		InitializeFncPtr _cleanupPtr;

		T* _target;
		Enum _currentState;
		Enum _nextState;
	public:
		StateMachineState(T* target,Enum currentState, InitializeFncPtr initializationPtr, UpdateFncPtr updatePtr, CleanupFncPtr cleanupPtr)
			: _target(target), _currentState(currentState),  _initializationPtr(initializationPtr), _updatePtr(updatePtr), _cleanupPtr(cleanupPtr)
		{
		};
		~StateMachineState(void)
		{
		};

		void Initialize(void)
		{
			(_target->*_initializationPtr)();
		};
		virtual void Update(const sf::Time& elapsedTIme, const sf::Time& totalElapsedTIme)
		{
			(_target->*_updatePtr)(elapsedTIme, totalElapsedTIme);
		};


		Enum GotoNext(void)
		{
			return (_target->_cleanupPtr)();
		};

		Enum GetState(void)
		{
			return _currentState;
		};
	};
}
